//package org
//import org.apache.spark.sql.SparkSession
//import org.apache.spark.sql.catalyst.dsl.expressions.{DslAttr, DslExpression, StringToAttributeConversionHelper}
//import org.apache.spark.sql.functions.{desc, user}
//import org.apache.spark.sql.types.{IntegerType, StringType, StructField, StructType}
//object sql3 {
//    def main(args:Array[String]):Unit={
//      val spark = SparkSession
//        .builder()
//        .master("local[*]")
//        .appName("spark")
//        .getOrCreate()
//      val sc=spark.sparkContext
//      val schemaUser=StructType(Seq(
//        StructField("id",IntegerType),
//        StructField("gender",StringType),
//        StructField("age",IntegerType),
//        StructField("occupation",IntegerType),
//        StructField("location",StringType)
//      ))
//      val user=spark.read.option("sep","::").schema(schemaUser)
//        .csv("src/main/resources/users.dat")
//      user.show(5)
//      user.where("gender='F' and age=18").show(3)
//      user.filter("gender='F' and age=18").show(3)
//      spark.udf.register("replace", (x:String) => {
//        x match {
//          case "M" => 0
//          case "F" => 1
//        }
//      })
//      user.selectExpr("id","replace(gender) as sexual","age").show(3)
//      user.select("id","age","location").show(3)
//      user.orderBy(desc("age")).show(5)
//      user.sort(-user("id")).show(5)
//      user.groupBy("gender").count().show()
//      val schemaMovie = new StructType()
//        .add("movie_id", IntegerType)
//        .add("title", StringType)
//      val movies = spark.read
//        .option("sep", "::")
//        .schema(schemaMovie)
//        .csv("src/main/resources/movies.dat")
////      val ratings = Seq(
////        (1, 101, 5),
////        (2, 102, 4),
////        (1, 103, 3)
////      ).toDF("user_id", "movie_id", "rating")
//      val users = spark.read
//        .option("sep", "::")
//        .schema(new StructType()
//          .add("id", IntegerType)
//          .add("age", IntegerType)
//          .add("gender", StringType)
//        )
//        .csv("src/main/resources/users.dat")
//      val movies = spark.read.option("sep", "::").schema(schemaMovie).csv("src/main/resources/movies.dat")
//      val result = users
//      user.filter("gender='F' and age=18").show(5)
//      user.join("user_id")
//      user.join("movie_id")
//      user.select("title")
//      user.distinct()
//      result.show()
//      sc.stop()
//    }
//}
